#include <bits/stdc++.h>

using namespace std;

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        priority_queue<long long,vector<long long>,greater<long long> > hp;
        long long ans=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            int t;
            scanf("%d",&t);
            hp.push(t);
        }
        for(int i=1;i<n;i++){
            long long x,y;
            x=hp.top();hp.pop();
            y=hp.top();hp.pop();
            x+=y;
            ans+=x;
            hp.push(x);
        }
        printf("%lld\n",ans);
    }
}
